<%
''读取json配置文件 和 全局配置文件(数据库)
class cls_config

Public key(),value(),data(),type(),form(),help()
private count,

''仅读入文件
Public function load(byval fname)
	dim pth : pth = lcase(cstr( server.mappth(fname) ))
	dim text : text = eu_getCache(pth)
	if eu_isnull(text) then
		text = eu_readfile(fname)
		setCache(pth, text)
	end if
	load = text
end function

''加载文件并读入到数组中 用于显示修改
Public function load2array(byval fname)
	dim text:text = load(fname)
	dim obj:set obj = eu_json_obj(text)
	dim keys:keys = eu_json_keys(obj)
	dim ka : ka = split(keys,",")
	count = ubound(k) - lbound(k)
	redim key(count)
	redim value(count)
	redim data(count)
	redim type(count)
	redim form(count)
	redim help(count)
	dim idx
	for idx=0 to count
		key(idx) = trim(ka(idx))
		execute("dim oo : set oo = obj."&key(idx) )
		value(idx) = eu_json_val("value", oo)
		data(idx) = eu_json_val("data", oo)
		type(idx) = eu_json_val("type", oo)
		form(idx) = eu_json_val("form", oo)
		help(idx) = eu_json_val("help", oo)
		set oo=nothing
	next
	set obj=nothing
end function

''通过key找到value  {config: model.article.title /}
Public function getByKey(byval opt)
	dim sp:sp = split(opt,".")
	if trim(sp(0)) = "common" then 
		Execute("getByKey = eucms_"&trim(sp(1))) ''直接是变量
	else
		getByKey = eu_getcache("config__"&opt)
		if eu_isnull(getByKey) then
			dim ikey:ikey = lcase(trim(sp(ubound(sp))))
			dim fname:fname = eu_confg_file(opt,"config")
			dim text:text = load(fname)
			dim obj:set obj = eu_json_obj(text)
			execute("dim oo : set oo = obj."&ikey )
			getByKey = eu_json_val("value", oo)
			if not eu_isnull(getByKey) then setcache("config__"&opt, getByKey)
			set oo=nothing
			set obj=nothing
		end if
	end if
end function

end class
%>
<script language="JScript" runat="server">
	function eu_json_obj( str ){
		var o= eval( "("+str+")" );
		return o;
	}
	function eu_json_keys(obj){
		var i=0,k;
		var karr=new Array();
		for(k in obj){
			karr[i++] = k;
		}
		return karr;
	}
	function eu_json_val(key, obj){
		return obj[key];
	}
</script>